﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Domain.Interface;
using Domain.Model;
using Newtonsoft.Json;
using WebAPI.Attributes;

namespace WebAPI.Controllers
{
    public class JiaoZhiGongController : ApiController
    {
        public IJiaoZhiGong _IJiaoZhiGong { set; get; }
        /// <summary>
        /// 新增员工
        /// </summary>
        /// <param name="zh">账号</param>
        /// <param name="xm"></param>
        /// <param name="xb"></param>
        /// <param name="sjh"></param>
        /// <param name="ksid"></param>
        /// <param name="zwid"></param>
        [HttpGet]
        public void AddJiaoZhiGongInfo(string zh, string xm, int xb, string sjh, int ksid, int zwid)
        {
            _IJiaoZhiGong.AddJiaoZhiGong(zh, xm, xb, sjh, ksid, zwid);
        }
        /// <summary>
        /// 更新员工
        /// </summary>
        /// <param name="userid">Guid</param>
        /// <param name="xm"></param>
        /// <param name="xb"></param>
        /// <param name="sjh"></param>
        /// <param name="ksid"></param>
        /// <param name="zwid"></param>
        [HttpGet]
        public void UpdateJiaoZhiGongInfo(string userid, string xm, int xb, string sjh, int ksid, int zwid)
        {
            _IJiaoZhiGong.UpdateJiaoZhiGong(userid, xm, xb, sjh, ksid, zwid);
        }
        [HttpPost, WriteFileExceptionAspect]
        public void UpdatePassword(dynamic obj)
        {
            _IJiaoZhiGong.UpdatePassword(obj.username.ToString(), obj.oldpassword.ToString(), obj.newpassword.ToString());
        }
        [HttpGet]
        public void DelJiaoZhiGongInfo(string userid)
        {
            _IJiaoZhiGong.DelJiaoZhiGong(userid);
        }

        public dynamic GetJiaoZhiGongs( int ksid, int zwid, int pageIndex, int pageSize, string keyword="")
        {
            int total;
            var str = _IJiaoZhiGong.GetJiaoZhiGongs(keyword, ksid, zwid, pageIndex, pageSize, out total);
            var lst = JsonConvert.DeserializeObject<List<Domain_JiaoZhiGong>>(str);
            dynamic obj = new { data = lst, total = total };
            return obj;
        }

        public Domain_JiaoZhiGong GetJiaoZhiGongInfo(string userid)
        {
            var str = _IJiaoZhiGong.GetJiaoZhiGongInfo(userid);
            var info = JsonConvert.DeserializeObject<Domain_JiaoZhiGong>(str);
            return info;
        }

        public Domain_JiaoZhiGong GetJiaoZhiGongInfoByUsername(string username)
        {
            var str = _IJiaoZhiGong.GetJiaoZhiGongInfoByUsername(username);
            var info = JsonConvert.DeserializeObject<Domain_JiaoZhiGong>(str);
            return info;
        }
        [HttpPost]
        public void ResetPassword(dynamic obj)
        {
            _IJiaoZhiGong.ResetPassword(obj.username.ToString());
        }
    }
}
